/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package bean;

import javax.enterprise.context.Dependent;
import javax.inject.Named;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import sessionbean.HelloBeanRemote;

/**
 *
 * @author VANANH
 */
@Named(value = "sayHello")
@Dependent
public class SayHello
{
    
    
    private String message;

    public String getMessage()
    {
        return message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }
    
    /**
     * Creates a new instance of SayHello
     */
    public SayHello()
    {
    }
    public String hello() throws NamingException{
        HelloBeanRemote bean = lookupHelloBeanRemote();
        setMessage(bean.getMessage());
        return "index";
    }

    private HelloBeanRemote lookupHelloBeanRemote() throws NamingException
    {
        //server khác đặt IP vào InitialContext
        InitialContext ic = new InitialContext();
        HelloBeanRemote remote = (HelloBeanRemote) ic.lookup("java:global/HelloModule/HelloBean!sessionbean.HelloBeanRemote");
        return remote;
    }
}
